package com.xjtu.platform.admin.user.Impl;

import com.xjtu.platform.admin.user.*;
import com.xjtu.platform.admin.user.dao.UserDao;
import com.xjtu.platform.common.Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao userDao;

    @Override
    public Map<String, Object> getUserList(UserDto userDto) {
        return Utils.getPage(userDto,()->userDao.findUser(userDto));
    }

    @Override
    public boolean addUser(NewUserDto newUserDto) {
        try {
            userDao.addUser(newUserDto);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean deleteUser(DeletedUserDto deletedUserDto) {
        try {
            userDao.deleteUser(deletedUserDto);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean changeRole(ChangeRoleDto changeRoleDto) {
        try {
            userDao.changeRole(changeRoleDto);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
